import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:work_tools/values/color.dart';
import 'package:work_tools/values/text_style.dart';
import 'package:work_tools/widget/button.dart';

class FinishedWhitelistWidget extends StatelessWidget {

  final String title;
  final String redisKey;
  final String redisValue;


  const FinishedWhitelistWidget({
    Key? key,
    required this.title,
    required this.redisKey,
    required this.redisValue,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child: Container(
        width: 700,
        height: 600,
        color: Colors.white,
        child: Column(
          children: [
            Container(
              margin: const EdgeInsets.only(top: 20),
              alignment: Alignment.center,
              child: Text("重置白名单",style: TStyleUtil.sc_5_14(ColorsValue.black2a)),
            ),
            const SizedBox(height: 20),
            groupTitle(title, redisValue),
            Container(
              padding: const EdgeInsets.only(left: 20, right: 20, top: 40),
              alignment: Alignment.centerLeft,
              child: Text(
                redisKey,
                style: TStyleUtil.sc_4_10(ColorsValue.grey3a),
              ),
            ),
            Container(
              padding: const EdgeInsets.only(left: 20, right: 20, top: 12),
              child: Text(
                redisValue,
                style: TStyleUtil.sc_4_10(ColorsValue.textGrey),
              ),
            ),
            const Spacer(),
            Container(
              alignment: Alignment.center,
              padding: const EdgeInsets.only(left: 40, right: 40),
              child: TextOutlinedButton(
                height: 44,
                title: "已经在管理后台完成设置",
                onTap: () => Get.back(),
              ),
            ),
            const Spacer(),
          ],
        ),
      ),
    );
  }

  Widget groupTitle(String title, String value) {
    return Row(
      children: [
        const SizedBox(width: 20),
        Text(title, style: TStyleUtil.sc_4_16(ColorsValue.black2a)),
        const SizedBox(width: 20),
        InkWell(
          onTap: () => copyData(redisKey),
          child: Text(
            "复制redis的key",
            style: TStyleUtil.sc_4_12(ColorsValue.blue3),
          ),
        ),
        const SizedBox(width: 20),
        InkWell(
          onTap: () => copyData(redisValue),
          child: Text(
            "复制redis的value",
            style: TStyleUtil.sc_4_12(ColorsValue.blue3),
          ),
        ),
      ],
    );
  }

  Future<void> copyData(String data) async {
    await Clipboard.setData(ClipboardData(text: data));
    ScaffoldMessenger.of(Get.context!).showSnackBar(const SnackBar(content: Text('内容复制完成')));
  }

  static Future<void> displaySheet(
      BuildContext ctx, {
        required String title,
        required String redisKey,
        required String redisValue,
      }) async {
    final res = await showModalBottomSheet(
      backgroundColor: Colors.transparent,
      isScrollControlled: true,
      context: ctx,
      builder: (BuildContext context) {
        return FinishedWhitelistWidget(
          title: title,
          redisKey: redisKey,
          redisValue: redisValue,
        );
      },
    );
    print("display sheet: ${res}");
  }
}
